﻿using DataBaseConnect.IRepositories;
using Entity;
using System;
using System.Collections.Generic;
using System.Text;
using Utils;

namespace DataBaseConnect.App
{
    public class LeaveAppService : ILeaveAppService
    {
        private readonly ILeaveRepository _leaveRepository;

        public LeaveAppService(ILeaveRepository leaveRepository)
        {
            _leaveRepository = leaveRepository;
        }

        /// <summary>
        ///  添加请假信息
        /// </summary>
        /// <param name="Input">参数实体</param>
        /// <returns></returns>
        public ReceiveStatus AddLeaveMsg(Leave Input)
        {
            ReceiveStatus receiveStatus = new ReceiveStatus();
            try
            {
                _leaveRepository.Insert(Input, true);
                receiveStatus.msg = "新增成功";
            }
            catch (Exception ex)
            {
                receiveStatus.code = statuCode.Error;
                receiveStatus.msg = ex.Message;
            }
            return receiveStatus;
        }

        /// <summary>
        /// 查询所有假单&&根据假单名称查询
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        public List<Leave> GetLeaveAllMsg(string Name)
        {
            if (!string.IsNullOrEmpty(Name))
            {
                return _leaveRepository.GetAllList(f => f.Name == Name);
            }
            else
            {
                return _leaveRepository.GetAllList();
            }
        }

        /// <summary>
        /// 根据id查询假单
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Leave GetLeaveIdMsg(int Id)
        {
            return _leaveRepository.FirstOrDefault(f => f.Id == Id);
        }
    }
}
